package com.yuzhitong.shapi.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.yuzhitong.shapi.R;
import com.yuzhitong.shapi.base.BaseLayoutActivity;
import com.yuzhitong.shapi.base.BaseMvpActivity;
import com.yuzhitong.shapi.contract.HelpContract;
import com.yuzhitong.shapi.presenter.HelpPresenter;
import com.yuzhitong.shapi.widget.FeedbackDialog;

/**
 * Created by Brsya
 * CreateDate: 2022/4/26  21:29
 * Description:
 * 帮助与反馈页面
 */
public class HelpActivity extends BaseMvpActivity<HelpPresenter> implements HelpContract.View,View.OnClickListener {

    private RelativeLayout llPageTitleBox;
    private TextView tvPageTitle;
    private LinearLayout llTitleBackBox;
    private LinearLayout llHelpMenu;
    private LinearLayout llMenuAd;
    private LinearLayout llMenuNet;
    private LinearLayout llMenuMy;
    private LinearLayout llMenuProposal;


    private FeedbackDialog feedbackDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        setDarkStatus();

        initView();
    }

    @Override
    protected void initPresenter() {
        presenter = new HelpPresenter();
        presenter.attachView(this);
    }

    private void initView() {
        llPageTitleBox = findViewById(R.id.ll_page_title_box);
        tvPageTitle = findViewById(R.id.tv_page_title);
        llTitleBackBox = findViewById(R.id.ll_title_back_box);
        llHelpMenu = findViewById(R.id.ll_help_menu);
        llMenuAd = findViewById(R.id.ll_menu_ad);
        llMenuNet = findViewById(R.id.ll_menu_net);
        llMenuMy = findViewById(R.id.ll_menu_my);
        llMenuProposal = findViewById(R.id.ll_menu_proposal);


        llPageTitleBox.setPadding(
                llPageTitleBox.getPaddingLeft(),
                llPageTitleBox.getPaddingTop() + getStatusBarHeight(),
                llPageTitleBox.getPaddingRight(),
                llPageTitleBox.getPaddingBottom()
        );

        llTitleBackBox.setOnClickListener(this);
        llMenuAd.setOnClickListener(this);
        llMenuNet.setOnClickListener(this);
        llMenuMy.setOnClickListener(this);
        llMenuProposal.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.ll_title_back_box) {
            finish();
        } else if (id == R.id.ll_menu_ad) {
            showFeedbackDialog(getResources().getString(R.string.help_menu_ad));
        } else if (id == R.id.ll_menu_net) {
            showFeedbackDialog(getResources().getString(R.string.help_menu_net));
        } else if (id == R.id.ll_menu_my) {
            showFeedbackDialog(getResources().getString(R.string.help_menu_my));
        } else if (id == R.id.ll_menu_proposal) {
            showFeedbackDialog(getResources().getString(R.string.help_menu_proposal));
        }
    }

    private void showFeedbackDialog(String type) {

        if (feedbackDialog == null) {
            feedbackDialog = new FeedbackDialog(this);
        }else{
            feedbackDialog.dismiss();
        }

        feedbackDialog.setOnClickBtnListener(new FeedbackDialog.OnClickBtnListener() {
            @Override
            public void onDismiss() {

            }

            @Override
            public void onConfirm(String feedback) {
                presenter.submit(type, feedback);
            }
        });
        feedbackDialog.show();
    }

    @Override
    public void submitSuccess() {
        feedbackDialog.dismiss();
        Toast.makeText(this, "提交成功", Toast.LENGTH_SHORT).show();
    }
}
